package cn.kshost.zqyg.order.controller;

import cn.kshost.zqyg.model.dto.h5.OrderInfoDto;
import cn.kshost.zqyg.model.entity.order.OrderInfo;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import cn.kshost.zqyg.model.vo.h5.TradeVo;
import cn.kshost.zqyg.order.service.OrderService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping("/api/order/orderInfo/auth")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @Operation(summary = "确认下单")
    @GetMapping("/trade")
    public Result trade() {
        System.out.println(123);
        TradeVo tradeVo =  orderService.trade();
        return Result.build(tradeVo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "提交订单")
    @PostMapping("/submitOrder")
    public Result<Long>  submitOrder(@Parameter(name = "orderInfoDto", description = "请求参数实体类", required = true) @RequestBody OrderInfoDto orderInfoDto){
        Long orderId = orderService.submitOrder(orderInfoDto);
        return Result.build(orderId, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据id获取订单信息")
    @GetMapping("/{orderId}")
    public Result<OrderInfo> getOrderInfo(@PathVariable Long orderId){
        OrderInfo orderInfo =  orderService.getOrderInfo(orderId);
        return Result.build(orderInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "购买单独商品")
    @GetMapping("/buy/{skuId}")
    public Result<OrderInfo> getBuyOrderInfo(@PathVariable Long skuId){
       TradeVo tradeVo =  orderService.getBuyOrderInfo(skuId);
       return Result.build(tradeVo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据订单状态查询订单列表")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<OrderInfo>> getOrderInfoPage(@PathVariable Integer page, @PathVariable Integer limit, @RequestParam(required = false,defaultValue = "") Integer orderStatus){
        PageInfo<OrderInfo> orderInfoPageInfo =  orderService.getOrderInfoPage(page,limit,orderStatus);
        return  Result.build(orderInfoPageInfo,ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "根据orderNo 查询订单信息")
    @GetMapping("/getOrderInfoByOrderNo/{orderNo}")
    public Result<OrderInfo> getOrderInfoByOrderNo(@PathVariable Long orderNo){
       OrderInfo orderInfo =   orderService.getOrderInfoByOrderNo(orderNo);
       return Result.build(orderInfo, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "通过orderNo更新订单状态和拆入订单日志")
    @GetMapping("/updateOrderStatus/{orderNo}/{payType}")
   public Result updateOrderStatus(@PathVariable("orderNo") String orderNo,@PathVariable("payType") Integer payType){

        orderService.updateOrderStatus(orderNo,payType);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }



}
